const Controller = require('egg').Controller

class DefaultController extends Controller {
  async index() {
    const { ctx, app } = this
    // const message = this.args[0]
    const nsp = app.io.of('/')
    const message = ctx.args[0] || {}
    const socket = ctx.socket
    const client = socket.id
    // console.log('nsp:', nsp)
    console.log('message:', message)
    console.log('client:', client)
    if (message.code === 0) {
      // emit 发送
      ctx.socket.emit(
        'send_data',
        `我是后端-devin-wang :--------> ${message.msg}`
      )
    } else {
      ctx.socket.emit('send_data', `我是nodejs工程师: --------> ${message.msg}`)
    }
    // ctx.body = 123
  }
}

module.exports = DefaultController
